package com.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.OrderBean;
import com.project.bean.OrderInfoBean;
import com.project.bean.UserBean;
import com.project.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private IOrderService orderService;
    @RequestMapping("findByItem")
    List<OrderBean> findByItem(String productType, LocalDate date, String userType){
        return orderService.findByItem(productType, date, userType);
    }
    @RequestMapping("findByUserPrice")
    IPage<UserBean> findByUserPrice(int page){
        return orderService.findByUserPrice(page);
    }
    @RequestMapping("cutOrderByItem")
    public IPage<OrderBean> cutOrderByItem(int page, String type, LocalDate startDate, LocalDate endDate){
        return orderService.cutOrderByItem(page, type, startDate, endDate);
    }

    /**
     * 通过订单ID查询订单明细
     * @param orderId 订单ID
     * @return 订单明细集合
     */
    @RequestMapping("findByOrderId")
    public List<OrderInfoBean> findByOrderId(String orderId){
        return  orderService.findByOrderId(orderId);
    }

    /**
     * 通过订单编号修改订单状态
     * @param orderNum 订单编号
     * @param status 订单状态
     */
    @RequestMapping("updateStatus")
    public String updateStatus(String orderNum,String status){
        return orderService.updateStatus(orderNum, status);
    }

    /**
     * 添加订单
     * @param orderBean 订单对象
     */
    @RequestMapping("addOrder")
    public String addOrder(OrderBean orderBean){
        return orderService.addOrder(orderBean);
    }
}
